//
//  main.c
//  模拟实现strcmp
//
//  Created by 卜绎皓 on 2022/3/26.
//

#include<stdio.h>
 
int My_Strcmp(char *p1, char *p2)
{
    
    if(*p1!='\0'  && *p2!='\0')
    {
        if(*p1 > *p2)
            return 1;
        else if(*p1 < *p2)
            return -1;
        else
        {
            p1++;
            p2++;
            return My_Strcmp(p1,p2);
        }
        
    }
    else if(*p1!='\0'  && *p2 =='\0')
        return 1;
    else if(*p1 =='\0'  && *p2 !='\0')
        return -1;
    else
        return 0;
        
}
 
 
int main()
{
    int i;
    char p1[] = "hello bit";
    char p2[] = "hello";
    i = My_Strcmp(p1,p2);
    if(i == 1)
        printf("p1>p2");
    else if(i == -1)
        printf("p1<p2");
    else
        printf("p1=p2");
    return 0;
}

